

;===================
;=                 =
;=   BEEPER FX     =
;=                 =
;===================
;


    .MODULE beepfx
    
set_fx
     add a, a
     ld hl, fx_table
     ld e, a
     ld d, 0
     add hl, de
     ld e, (hl)
     inc hl
     ld d, (hl)
     ld (_play1), de
play_fx
     ld hl, (_play1)
     ld e, (hl)
     inc hl
     ld d, (hl)
     inc hl
     ld (_play1), hl
     ex de, hl
     ld a, h
     or a
     jr nz, tone_exec
     ld a, l
     or a
     jr nz, noise_exec
     ld hl, (_play1)
     dec hl
     dec hl
     ld (_play1), hl
     xor a
     ld r, a
_playfx1
     ld a, r
     ret m
     jr _playfx1
_play1
    .WORD 0


; TONE:
;  H = SPEAKER ON 
;  L = SPEAKER OFF
;
; NOISE:
;  L = NOISE PITCH 



  .MODULE beepfx_exec
tone_exec
	xor a
	ld r, a		;semaphor for note routine ->  R,b7
	ld bc, 254	;beeper port
_tone4
	ld e, l
_tone1
	ld a, r		;8
	ret m		;5
	dec e		;4
	jr z, _tone1	;12 29

	ld a, 16
	out (c), a
	ld e, h
_tone2
	ld a, r
	ret m
	dec e
	jr z, _tone2
	xor a
	out (c), a
	jr _tone4
noise_exec
	xor a
	ld r, a
	ld de, 256
	ld bc, 254
_noise1
	ld h, l
_noise2 
	ld a, r		;8
	ret m		;5
	dec h		;4
	jr z, _noise2	;12
	ld a, (de)
	inc e
	and 16
	out (c), a
	jr _noise1

	